package com.weiyi.mashangzhu.Landlord.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.donkingliang.imageselector.utils.ImageSelectorUtils;
import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.Landlord.Bean.PhotoBean;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Utils.BitmapUtils;
import com.weiyi.mashangzhu.Utils.GlideImgManager;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ApproveActivity extends BaseActivity {

    List<String> photoslist1 = new ArrayList<>();
    @BindView(R.id.name)
    EditText name;
    @BindView(R.id.card)
    EditText card;
    @BindView(R.id.add_1)
    RelativeLayout add1;
    @BindView(R.id.iv_add_1)
    ImageView ivAdd1;
    @BindView(R.id.add_2)
    RelativeLayout add2;
    @BindView(R.id.iv_add_2)
    ImageView ivAdd2;
    @BindView(R.id.add_3)
    RelativeLayout add3;
    @BindView(R.id.iv_add_3)
    ImageView ivAdd3;
    @BindView(R.id.re_iv3)
    RelativeLayout reIv3;
    @BindView(R.id.re_iv1)
    RelativeLayout reIv1;
    @BindView(R.id.re_iv2)
    RelativeLayout reIv2;
    @BindView(R.id.close1)
    ImageView close1;
    @BindView(R.id.close2)
    ImageView close2;
    @BindView(R.id.close3)
    ImageView close3;
    String info;
    String id;
    List<PhotoBean> url_get = new ArrayList<>();
    List<PhotoBean> url = new ArrayList<>();
    List<PhotoBean> url_post = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_approve);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        info = intent.getStringExtra("info");
        id = intent.getStringExtra("id");
        if (info.equals("post")) {
            initPhoto(MyApp.images_id);
        } else {
            LoadingDialog.show(this);
            OkHttpUtils.get()
                    .addParams("token", SPUtils.get(this, "token", "") + "")
                    .addParams("id", id)
                    .url(API.BaseApi_L + API.GetHouseApprove_Api)
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {
                            LoadingDialog.dismiss(ApproveActivity.this);
                            T.showShort(ApproveActivity.this, "数据加载失败，请稍后再试");
                        }

                        @Override
                        public void onResponse(String response) {
                            LoadingDialog.dismiss(ApproveActivity.this);
                            Log.e("aaaaaaaaaaaaa", "re=" + response);
                            try {
                                JSONObject jsonObject = new JSONObject(response);
                                Log.e("aaaaaaaaaaaaa", "re=" + jsonObject.getInt("status"));
                                if (jsonObject.getInt("status") == 0) {
                                    JSONArray jsonArray = jsonObject.getJSONArray("data");
                                    JSONObject jsonObject1 = jsonArray.getJSONObject(0);
                                    name.setText(jsonObject1.getString("hRealname"));
                                    card.setText(jsonObject1.getString("hIdcardnum"));
                                    add1.setVisibility(View.GONE);
                                    add2.setVisibility(View.GONE);
                                    add3.setVisibility(View.GONE);
                                    reIv1.setVisibility(View.VISIBLE);
                                    reIv2.setVisibility(View.VISIBLE);
                                    reIv3.setVisibility(View.VISIBLE);
                                    url_get.add(new PhotoBean("get", jsonObject1.getString("hIdpic1")));
                                    url_get.add(new PhotoBean("get", jsonObject1.getString("hIdpic2")));
                                    url_get.add(new PhotoBean("get", jsonObject1.getString("hIdpic3")));
                                    url.add(new PhotoBean("get", jsonObject1.getString("hIdpic1")));
                                    url.add(new PhotoBean("get", jsonObject1.getString("hIdpic2")));
                                    url.add(new PhotoBean("get", jsonObject1.getString("hIdpic3")));
                                    initPhoto_edit();
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });
        }

    }

    private void initPhoto_edit() {
        if (url.size() == 0) {
            add1.setVisibility(View.VISIBLE);
            reIv1.setVisibility(View.INVISIBLE);
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.INVISIBLE);
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 3);
                }
            });

        } else if (url.size() == 1) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            if (url.get(0).getInfo().equals("post")) {
                File file = new File(url.get(0).getUrl());
                Glide.with(this).load(file).into(ivAdd1);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url_get.get(0).getUrl(), R.mipmap.errer, ivAdd1);
            }
            add2.setVisibility(View.VISIBLE);
            reIv2.setVisibility(View.INVISIBLE);
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 2);
                }
            });
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (url_get.size() >= 1) {
                        url_get.remove(0);
                    } else {
                        url_post.remove(0);
                    }
                    url.remove(0);
                    initPhoto_edit();
//                        reIv1.setVisibility(View.VISIBLE);

                }
            });
        } else if (url.size() == 2) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            if (url.get(0).getInfo().equals("post")) {
                File file = new File(url.get(0).getUrl());
                Glide.with(this).load(file).into(ivAdd1);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url.get(0).getUrl(), R.mipmap.errer, ivAdd1);
            }
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.VISIBLE);
            if (url.get(1).getInfo().equals("post")) {
                File file = new File(url.get(1).getUrl());
                Glide.with(this).load(file).into(ivAdd2);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url.get(1).getUrl(), R.mipmap.errer, ivAdd2);
            }
            add3.setVisibility(View.VISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 1);
                }
            });
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (url_get.size() >= 1) {
                        url_get.remove(0);
                    } else {
                        url_post.remove(0);
                    }
                    url.remove(0);
                    initPhoto_edit();
                }
            });
            close2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (url_get.size() == 0) {


//                        if (url_get.size() == 0) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(1);
//                        }
                    } else if (url_get.size() == 1) {

//                        if (url_get.size() == 1) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(0);
//                        }
                    } else if (url_get.size() == 2) {
//                        if (url_get.size() == 2) {
                        url_get.remove(1);
//                        } else {
////                            url_post.remove(0);
//                        }
                    } else if (url_get.size() == 3) {
//                        if (url_get.size() == 3) {
                        url_get.remove(1);
//                        } else {
////                            url_post.remove(0);
//                        }
                    }


                    url.remove(1);
                    initPhoto_edit();
                }
            });

        } else if (url.size() == 3) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            if (url.get(0).getInfo().equals("post")) {
                File file = new File(url.get(0).getUrl());
                Glide.with(this).load(file).into(ivAdd1);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url.get(0).getUrl(), R.mipmap.errer, ivAdd1);
            }
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.VISIBLE);
            if (url.get(1).getInfo().equals("post")) {
                File file = new File(url.get(1).getUrl());
                Glide.with(this).load(file).into(ivAdd2);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url.get(1).getUrl(), R.mipmap.errer, ivAdd2);
            }
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.VISIBLE);
            if (url.get(2).getInfo().equals("post")) {
                File file = new File(url.get(2).getUrl());
                Glide.with(this).load(file).into(ivAdd3);
            } else {
                GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + url.get(2).getUrl(), R.mipmap.errer, ivAdd3);
            }
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (url_get.size() >= 1) {
                        url_get.remove(0);
                    } else {
                        url_post.remove(0);
                    }
                    url.remove(0);
                    initPhoto_edit();
                }
            });
            close2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (url_get.size() == 0) {

//                        if (url_get.size() == 0) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(1);
//                        }
                    } else if (url_get.size() == 1) {
//                        if (url_get.size() == 1) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(0);
//                        }
                    } else if (url_get.size() == 2) {
//                        if (url_get.size() == 2) {
                        url_get.remove(1);
//                        } else {
////                            url_post.remove(0);
//                        }
                    } else if (url_get.size() == 3) {
//                        if (url_get.size() == 3) {
                        url_get.remove(1);
//                        } else {
////                            url_post.remove(0);
//                        }
                    }


                    url.remove(1);
                    initPhoto_edit();
                }
            });
            close3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (url_get.size() == 0) {
//                        if (url_get.size() == 0) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(2);
//                        }
                    } else if (url_get.size() == 1) {
//                        if (url_get.size() == 1) {
////                            url_get.remove(1);
//                        } else {
                        url_post.remove(1);
//                        }
                    } else if (url_get.size() == 2) {
//                        if (url_get.size() == 2) {
////                            url_get.remove(0);
//                        } else {
                        url_post.remove(0);
//                        }
                    } else if (url_get.size() == 3) {
//                        if (url_get.size() == 3) {
                        url_get.remove(2);
//                        } else {
////                            url_post.remove(0);
//                        }
                    }
                    url.remove(2);
                    initPhoto_edit();
                }
            });
        }
//            GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + jsonObject1.getString("hIdpic1"), R.mipmap.errer, ivAdd1);
//            GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + jsonObject1.getString("hIdpic2"), R.mipmap.errer, ivAdd2);
//            GlideImgManager.glideLoader(ApproveActivity.this, API.BaseApi_url + jsonObject1.getString("hIdpic3"), R.mipmap.errer, ivAdd3);
//            close1.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//
//                }
//            });
//            close2.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (url_get.size() >= 2) {
//                        url_get.remove(1);
//                    } else {
//                        if (url_get.size() == 1) {
//                            url_post.remove(0);
//                        } else if (url_get.size() == 0) {
//                            url_post.remove(1);
//                        }
//
//                    }
//                }
//            });
//            close3.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (url_get.size() == 3) {
//                        url_get.remove(2);
//                    } else {
//                        if (url_get.size() == 1) {
//                            url_post.remove(1);
//                        } else if (url_get.size() == 0) {
//                            url_post.remove(2);
//                        } else if (url_get.size() == 2) {
//                            url_post.remove(0);
//                        }
//
//                    }
//                }
//            });
//        }else {
//            T.showShort(ApproveActivity.this,"请完善图片信息");
//        }
        Log.e("aaaaaaaaaaaa", "url.size=" + url.size() + ",url_get.size" + url_get.size() + ",url_post.size" + url_post.size());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x001 && data != null) {
            //获取选择器返回的数据
            if (info.equals("post")) {
                MyApp.images_id.addAll(data.getStringArrayListExtra(
                        ImageSelectorUtils.SELECT_RESULT));
                initPhoto(MyApp.images_id);
            } else {
                for (int i = 0; i < data.getStringArrayListExtra(
                        ImageSelectorUtils.SELECT_RESULT).size(); i++) {
                    url_post.add(new PhotoBean("post", data.getStringArrayListExtra(
                            ImageSelectorUtils.SELECT_RESULT).get(i)));
                    url.add(new PhotoBean("post", data.getStringArrayListExtra(
                            ImageSelectorUtils.SELECT_RESULT).get(i)));
                    initPhoto_edit();
                }
            }


        }
    }

    public void initPhoto(List<String> list) {
        if (MyApp.realname != null) {
            name.setText(MyApp.realname);
        }
        if (MyApp.idcard != null) {
            card.setText(MyApp.idcard);
        }
        if (list.size() == 0) {
            add1.setVisibility(View.VISIBLE);
            reIv1.setVisibility(View.INVISIBLE);
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.INVISIBLE);
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 3);
                }
            });
        } else if (list.size() == 1) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            File file = new File(list.get(0));
            Glide.with(this).load(file).into(ivAdd1);
            add2.setVisibility(View.VISIBLE);
            reIv2.setVisibility(View.INVISIBLE);
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 2);
                }
            });
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(0);
                    initPhoto(MyApp.images_id);

                }
            });
        } else if (list.size() == 2) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            File file = new File(list.get(0));
            Glide.with(this).load(file).into(ivAdd1);
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.VISIBLE);
            File file2 = new File(list.get(1));
            Glide.with(this).load(file2).into(ivAdd2);
            add3.setVisibility(View.VISIBLE);
            reIv3.setVisibility(View.INVISIBLE);
            add3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 1);
                }
            });
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(0);
                    initPhoto(MyApp.images_id);

                }
            });
            close2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(1);
                    initPhoto(MyApp.images_id);
                }
            });
        } else if (list.size() == 3) {
            add1.setVisibility(View.INVISIBLE);
            reIv1.setVisibility(View.VISIBLE);
            File file = new File(list.get(0));
            Glide.with(this).load(file).into(ivAdd1);
            add2.setVisibility(View.INVISIBLE);
            reIv2.setVisibility(View.VISIBLE);
            File file2 = new File(list.get(1));
            Glide.with(this).load(file2).into(ivAdd2);
            add3.setVisibility(View.INVISIBLE);
            reIv3.setVisibility(View.VISIBLE);
            File file3 = new File(list.get(2));
            Glide.with(this).load(file3).into(ivAdd3);
            add3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageSelectorUtils.openPhoto(ApproveActivity.this, 0x001, false, 1);
                }
            });
            close1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(0);
                    initPhoto(MyApp.images_id);
                }
            });
            close2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(1);
                    initPhoto(MyApp.images_id);
                }
            });
            close3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyApp.images_id.remove(2);
                    initPhoto(MyApp.images_id);
                }
            });
        }
    }

    @OnClick({R.id.back, R.id.baocun})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.baocun:
                if (info.equals("post")) {
                    if ((name.getText() + "").equals("")) {
                        T.showShort(this, "请输入真实姓名");
                    } else {
                        if ((card.getText() + "").equals("")) {
                            T.showShort(this, "请输入身份证号");
                        } else {
                            if (MyApp.images_id.size() == 3) {
                                LoadingDialog.show(this);
                                for (int i = 0; i < MyApp.images_id.size(); i++) {
                                    BitmapUtils.getBitmap(MyApp.images_id.get(i), 270, 480, "id" + i + MyApp.images_id.get(i).substring(MyApp.images_id.get(i).lastIndexOf("/") + 1));
                                    photoslist1.add("id" + i + MyApp.images_id.get(i).substring(MyApp.images_id.get(i).lastIndexOf("/") + 1));
                                }
                                File file1 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(0));
                                File file2 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(1));
                                File file3 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(2));
                                OkHttpUtils.post()
                                        .addParams("token", SPUtils.get(this, "token", "") + "")
                                        .addParams("hRealname", name.getText() + "")
                                        .addParams("hIdcardnum", card.getText() + "")
                                        .addFile("hIdpic1", photoslist1.get(0), file1)
                                        .addFile("hIdpic2", photoslist1.get(1), file2)
                                        .addFile("hIdpic3", photoslist1.get(2), file3)
                                        .url(API.BaseApi_L + API.CheckIdCard_Api_L).build().execute(new StringCallback() {
                                    @Override
                                    public void onError(Request request, Exception e) {
                                        LoadingDialog.dismiss(ApproveActivity.this);
                                        T.showShort(ApproveActivity.this, "获取数据失败，请稍后再试");
                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        LoadingDialog.dismiss(ApproveActivity.this);
                                        try {
                                            JSONObject jsonObject = new JSONObject(response);
                                            if (jsonObject.getInt("status") == 0) {
                                                T.showShort(ApproveActivity.this, "审核身份成功");
                                                JSONObject jsonObject1 = jsonObject.getJSONObject("data");
                                                JSONArray jsonArray = jsonObject1.getJSONArray("idcardImglist");
                                                if (jsonArray.length() == 3) {
                                                    MyApp.id1 = jsonArray.getString(0);
                                                    MyApp.id2 = jsonArray.getString(1);
                                                    MyApp.id3 = jsonArray.getString(2);
                                                    MyApp.realname = name.getText() + "";
                                                    MyApp.idcard = card.getText() + "";
                                                    Intent intent = new Intent();
                                                    intent.putExtra("info", "完成");
                                                    setResult(0x007, intent);
                                                    finish();
                                                }
                                            } else {
                                                T.showShort(ApproveActivity.this, "审核身份失败");
                                            }
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }

                                    }
                                });
                            } else {
                                T.showShort(this, "请提交完整图片信息");
                            }
                        }
                    }
                } else {
                    if ((name.getText() + "").equals("")) {
                        T.showShort(this, "请输入真实姓名");
                    } else {
                        if ((card.getText() + "").equals("")) {
                            T.showShort(this, "请输入身份证号");
                        } else {
                            if (url.size() == 3) {
                                if (url_post.size() == 0) {
                                    T.showShort(ApproveActivity.this, "未修改认证信息");

                                } else if (url_post.size() == 1) {
                                    for (int i = 0; i < url_post.size(); i++) {
                                        BitmapUtils.getBitmap(url_post.get(i).getUrl(), 270, 480, "id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                        photoslist1.add("id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                    }
                                    File file1 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(0));
//                                File file2 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(1));
//                                File file3 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(2));
                                    OkHttpUtils.post()
                                            .addParams("token", SPUtils.get(this, "token", "") + "")
                                            .addParams("hRealname", name.getText() + "")
                                            .addParams("hIdcardnum", card.getText() + "")
                                            .addFile("hIdpic1", photoslist1.get(0), file1)
//                                        .addFile("hIdpic2", photoslist1.get(1), file2)
//                                        .addFile("hIdpic3", photoslist1.get(2), file3)
                                            .url(API.BaseApi_L + API.CheckIdCard_Api_L).build().execute(new StringCallback() {
                                        @Override
                                        public void onError(Request request, Exception e) {
                                            T.showShort(ApproveActivity.this, "获取数据失败，请稍后再试");
                                        }

                                        @Override
                                        public void onResponse(String response) {
//
                                            try {
                                                JSONObject jsonObject = new JSONObject(response);
                                                if (jsonObject.getInt("status") == 0) {
                                                    JSONObject jsonObject1 = jsonObject.getJSONObject("data");
                                                    JSONArray jsonArray = jsonObject1.getJSONArray("idcardImglist");
                                                    List<String> list = new ArrayList<String>();
                                                    for (int i = 0; i < url_get.size(); i++) {
                                                        list.add(url_get.get(i).getUrl());
                                                    }
                                                    for (int i = 0; i < jsonArray.length(); i++) {
                                                        list.add(jsonArray.get(i) + "");
                                                    }
                                                    if (list.size() == 3) {
                                                        OkHttpUtils.get()
                                                                .addParams("token", SPUtils.get(ApproveActivity.this, "token", "") + "")
                                                                .addParams("id", id)
                                                                .addParams("hRealname", name.getText() + "")
                                                                .addParams("hIdcardnum", card.getText() + "")
                                                                .addParams("hIdpic1", list.get(0))
                                                                .addParams("hIdpic2", list.get(1))
                                                                .addParams("hIdpic3", list.get(2))
                                                                .url(API.BaseApi_L + API.UpdateApprove_api)
                                                                .build()
                                                                .execute(new StringCallback() {
                                                                    @Override
                                                                    public void onError(Request request, Exception e) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        T.showShort(ApproveActivity.this, "数据获取失败，请稍后再试");
                                                                    }

                                                                    @Override
                                                                    public void onResponse(String response) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        try {
                                                                            JSONObject j = new JSONObject(response);
                                                                            if (j.getInt("status") == 0) {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg") + " 后台审核中...");
                                                                                finish();
                                                                            } else {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg"));
                                                                            }
                                                                        } catch (JSONException e) {
                                                                            e.printStackTrace();
                                                                        }
                                                                    }
                                                                });


                                                    }

                                                } else {
                                                    T.showShort(ApproveActivity.this, jsonObject.getString("msg"));
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                    });

                                } else if (url_post.size() == 2) {
                                    for (int i = 0; i < url_post.size(); i++) {
                                        BitmapUtils.getBitmap(url_post.get(i).getUrl(), 270, 480, "id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                        photoslist1.add("id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                    }
                                    File file1 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(0));
                                    File file2 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(1));
//                                File file3 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(2));
                                    OkHttpUtils.post()
                                            .addParams("token", SPUtils.get(this, "token", "") + "")
                                            .addParams("hRealname", name.getText() + "")
                                            .addParams("hIdcardnum", card.getText() + "")
                                            .addFile("hIdpic1", photoslist1.get(0), file1)
                                            .addFile("hIdpic2", photoslist1.get(1), file2)
//                                        .addFile("hIdpic3", photoslist1.get(2), file3)
                                            .url(API.BaseApi_L + API.CheckIdCard_Api_L).build().execute(new StringCallback() {
                                        @Override
                                        public void onError(Request request, Exception e) {
                                            LoadingDialog.dismiss(ApproveActivity.this);
                                            T.showShort(ApproveActivity.this, "获取数据失败，请稍后再试");
                                        }

                                        @Override
                                        public void onResponse(String response) {
                                            LoadingDialog.dismiss(ApproveActivity.this);
//
                                            try {
                                                JSONObject jsonObject = new JSONObject(response);
                                                if (jsonObject.getInt("status") == 0) {
                                                    JSONObject jsonObject1 = jsonObject.getJSONObject("data");
                                                    JSONArray jsonArray = jsonObject1.getJSONArray("idcardImglist");
                                                    List<String> list = new ArrayList<String>();
                                                    for (int i = 0; i < url_get.size(); i++) {
                                                        list.add(url_get.get(i).getUrl());
                                                    }
                                                    for (int i = 0; i < jsonArray.length(); i++) {
                                                        list.add(jsonArray.get(i) + "");
                                                    }
                                                    if (list.size() == 3) {
                                                        OkHttpUtils.get()
                                                                .addParams("token", SPUtils.get(ApproveActivity.this, "token", "") + "")
                                                                .addParams("id", id)
                                                                .addParams("hRealname", name.getText() + "")
                                                                .addParams("hIdcardnum", card.getText() + "")
                                                                .addParams("hIdpic1", list.get(0))
                                                                .addParams("hIdpic2", list.get(1))
                                                                .addParams("hIdpic3", list.get(2))
                                                                .url(API.BaseApi_L + API.UpdateApprove_api)
                                                                .build()
                                                                .execute(new StringCallback() {
                                                                    @Override
                                                                    public void onError(Request request, Exception e) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        T.showShort(ApproveActivity.this, "数据获取失败，请稍后再试");
                                                                    }

                                                                    @Override
                                                                    public void onResponse(String response) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        try {
                                                                            JSONObject j = new JSONObject(response);
                                                                            if (j.getInt("status") == 0) {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg") + " 后台审核中...");
                                                                                finish();
                                                                            } else {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg"));
                                                                            }
                                                                        } catch (JSONException e) {
                                                                            e.printStackTrace();
                                                                        }
                                                                    }
                                                                });


                                                    }

                                                } else {
                                                    T.showShort(ApproveActivity.this, jsonObject.getString("msg"));
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                    });

                                } else if (url_post.size() == 3) {
                                    for (int i = 0; i < url_post.size(); i++) {
                                        BitmapUtils.getBitmap(url_post.get(i).getUrl(), 270, 480, "id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                        photoslist1.add("id" + i + url_post.get(i).getUrl().substring(url_post.get(i).getUrl().lastIndexOf("/") + 1));
                                    }
                                    File file1 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(0));
                                    File file2 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(1));
                                    File file3 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(2));
                                    OkHttpUtils.post()
                                            .addParams("token", SPUtils.get(this, "token", "") + "")
                                            .addParams("hRealname", name.getText() + "")
                                            .addParams("hIdcardnum", card.getText() + "")
                                            .addFile("hIdpic1", photoslist1.get(0), file1)
                                            .addFile("hIdpic2", photoslist1.get(1), file2)
                                            .addFile("hIdpic3", photoslist1.get(2), file3)
                                            .url(API.BaseApi_L + API.CheckIdCard_Api_L).build().execute(new StringCallback() {
                                        @Override
                                        public void onError(Request request, Exception e) {
                                            LoadingDialog.dismiss(ApproveActivity.this);
                                            T.showShort(ApproveActivity.this, "获取数据失败，请稍后再试");
                                        }

                                        @Override
                                        public void onResponse(String response) {
                                            LoadingDialog.dismiss(ApproveActivity.this);
//
                                            try {
                                                JSONObject jsonObject = new JSONObject(response);
                                                if (jsonObject.getInt("status") == 0) {
                                                    JSONObject jsonObject1 = jsonObject.getJSONObject("data");
                                                    JSONArray jsonArray = jsonObject1.getJSONArray("idcardImglist");
                                                    List<String> list = new ArrayList<String>();
                                                    for (int i = 0; i < url_get.size(); i++) {
                                                        list.add(url_get.get(i).getUrl());
                                                    }
                                                    for (int i = 0; i < jsonArray.length(); i++) {
                                                        list.add(jsonArray.get(i) + "");
                                                    }
                                                    if (list.size() == 3) {
                                                        OkHttpUtils.get()
                                                                .addParams("token", SPUtils.get(ApproveActivity.this, "token", "") + "")
                                                                .addParams("id", id)
                                                                .addParams("hRealname", name.getText() + "")
                                                                .addParams("hIdcardnum", card.getText() + "")
                                                                .addParams("hIdpic1", list.get(0))
                                                                .addParams("hIdpic2", list.get(1))
                                                                .addParams("hIdpic3", list.get(2))
                                                                .url(API.BaseApi_L + API.UpdateApprove_api)
                                                                .build()
                                                                .execute(new StringCallback() {
                                                                    @Override
                                                                    public void onError(Request request, Exception e) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        T.showShort(ApproveActivity.this, "数据获取失败，请稍后再试");
                                                                    }

                                                                    @Override
                                                                    public void onResponse(String response) {
                                                                        LoadingDialog.dismiss(ApproveActivity.this);
                                                                        try {
                                                                            JSONObject j = new JSONObject(response);
                                                                            if (j.getInt("status") == 0) {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg") + " 后台审核中...");
                                                                                finish();
                                                                            } else {
                                                                                T.showShort(ApproveActivity.this, j.getString("msg"));
                                                                            }
                                                                        } catch (JSONException e) {
                                                                            e.printStackTrace();
                                                                        }
                                                                    }
                                                                });


                                                    }

                                                } else {
                                                    T.showShort(ApproveActivity.this, jsonObject.getString("msg"));
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                    });

                                }


                            } else {
                                T.showShort(this, "请提交完整图片信息");
                            }
//                                LoadingDialog.show(this);
//                                for (int i = 0; i < MyApp.images_id.size(); i++) {
//                                    BitmapUtils.getBitmap(MyApp.images_id.get(i), 270, 480, "id" + i + MyApp.images_id.get(i).substring(MyApp.post_url.get(i).getUrl().lastIndexOf("/") + 1));
//                                    photoslist1.add("id" + i + MyApp.images_id.get(i).substring(MyApp.post_url.get(i).getUrl().lastIndexOf("/") + 1));
//                                }
//                                File file1 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(0));
//                                File file2 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(1));
//                                File file3 = new File(Environment.getExternalStorageDirectory(), photoslist1.get(2));
//                                OkHttpUtils.post()
//                                        .addParams("token", SPUtils.get(this, "token", "") + "")
//                                        .addParams("hRealname", name.getText() + "")
//                                        .addParams("hIdcardnum", card.getText() + "")
//                                        .addFile("hIdpic1", photoslist1.get(0), file1)
//                                        .addFile("hIdpic2", photoslist1.get(1), file2)
//                                        .addFile("hIdpic3", photoslist1.get(2), file3)
//                                        .url(API.BaseApi_L + API.CheckIdCard_Api_L).build().execute(new StringCallback() {
//                                    @Override
//                                    public void onError(Request request, Exception e) {
//                                        LoadingDialog.dismiss(ApproveActivity.this);
//                                        T.showShort(ApproveActivity.this, "获取数据失败，请稍后再试");
//                                    }
//
//                                    @Override
//                                    public void onResponse(String response) {
//                                        LoadingDialog.dismiss(ApproveActivity.this);
//                                        try {
//                                            JSONObject jsonObject = new JSONObject(response);
//                                            if (jsonObject.getInt("status") == 0) {
//                                                T.showShort(ApproveActivity.this, "审核身份成功");
//                                                JSONObject jsonObject1 = jsonObject.getJSONObject("data");
//                                                JSONArray jsonArray = jsonObject1.getJSONArray("idcardImglist");
//                                                if (jsonArray.length() == 3) {
//                                                    MyApp.id1 = jsonArray.getString(0);
//                                                    MyApp.id2 = jsonArray.getString(1);
//                                                    MyApp.id3 = jsonArray.getString(2);
//                                                    MyApp.realname = name.getText() + "";
//                                                    MyApp.idcard = card.getText() + "";
//                                                    Intent intent = new Intent();
//                                                    intent.putExtra("info", "完成");
//                                                    setResult(0x007, intent);
//                                                    finish();
//                                                }
//                                            } else {
//                                                T.showShort(ApproveActivity.this, "审核身份失败");
//                                            }
//                                        } catch (JSONException e) {
//                                            e.printStackTrace();
//                                        }
//
//                                    }
//                                });
//
                        }
                    }
                }


                break;
        }
    }

}
